<template>
  <!--试验任务进度-->
  <div class="app-container" v-dialog-drag>
    <el-dialog title="进度" :visible.sync="dialogVisible" align="center">
      <el-steps :active="activeStep" align-center>
        <el-step v-for="item in processList" :title="item.title" description="item.time" :key="item.title">
          <template slot="description" >
                 <span>{{item.user_id}}<br/>{{item.time}}</span>
            </template>
        </el-step>
      </el-steps>
    </el-dialog>

  </div>
</template>

<script>
import { progre } from '@/api/maintain'

export default {
  name: 'inspectionTaskProcess',
  data() {
    return {
        dialogVisible: false,
        activeStep: 0,
        processList: [
            {
            title: '已提交',
            status: 0,
            time:'',
            user_id:''
        },
          {
            title: '派单',
            status: 1,
            time: ''
        },{
            title: '接收',
            status: 2,
            time: ''
        },{
            title: '完成',
            status: 3,
            time: ''
        },{
            title: '确认',
            status: 4,
            time: ''
        },]
    }
  },
  methods: {
      // 打开弹窗
    open(row) {
      // 修改打开弹窗的变量为true，就可以打开弹窗了
      this.dialogVisible = true;
     
      // 调接口，获取详细数据
      const data = {
        task_num: row.work_num
      }
      // 派单时间
            // 派单时间
      this.processList[0].time = row.created_at ;
      this.processList[0].user_id =row.user_name
      progre(data).then(res => {

        //   debugger
        let dataList = res.data.list;
         let num=dataList.length
        if(num>0){
           // 设置进度
      this.activeStep = row.task_status+1;
           this.processList.forEach(item=>{
              dataList.forEach((item1,index1) => {

                if(item.status==item1.task_status){
                  console.log(item.status)
                  item.time=item1.created_at
                  item.user_id=item1.user_id
                }
                // this.processList[index].time=item.created_at
              })
           })
           console.log('进度', this.processList)
          
        }else{
           // 设置进度
      this.activeStep = 1;
          this.processList= [
              {
            title: '已提交',
            status: 0,
            time:'',
            user_id:''
        },{
            title: '派单',
            status: 1,
            time: ''
        },{
            title: '接收',
            status: 2,
            time: ''
        },{
            title: '完成',
            status: 3,
            time: ''
        },{
            title: '确认',
            status: 4,
            time: ''
        },]
         this.processList[0].time = row.created_at ;
      this.processList[0].user_id =row.user_name
        }
      })
    }
  }
}

</script>

<style scoped>

</style>
